package javamusic.Servlet.ReservaCliente;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javamusic.negocio.GestionReservaCliente;
import javamusic.negocio.GestionSala;
import javamusic.util.ConexionBDKaraoke;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServletReservaClienteInsertar
 */
@WebServlet("/ServletReservaClienteInsertar")
public class ServletReservaClienteInsertar extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletReservaClienteInsertar() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
		
		String fecha = request.getParameter("fecha");
		String descripcion = request.getParameter("descripcion");
		
		String idsala1 = request.getParameter("idsala");
		int idsala = Integer.parseInt(idsala1);
				
		
		String correo = "jose@gmail.com";
		
		
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		
    	
				
				
		

		
		try {
			
			con = ConexionBDKaraoke.obtenerConexion();
			String query = "select idcliente from cliente where correo = (" + correo + ")";
			stmt = con.prepareStatement(query);
			rs = stmt.executeQuery();
			System.out.println(rs);
			
			//con.prepareStatement(query);
			//stmt.setString(5,correo);
			//return stm;
			//System.out.println(query);
			
			GestionReservaCliente negocio = new GestionReservaCliente();
			
			negocio.insertar(fecha, descripcion, idsala, correo);
			
			
			RequestDispatcher rd = request.getRequestDispatcher("principal.jsp");
			rd.forward(request, response);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		
		
	}

}
